;; File              : init.el
;; Author            : gotpl <631707329@qq.com>
;; Date              : 2024-05-22 15:50:25
;; Last Modified Date: 2024-05-22 15:50:25
;; Last Modified By  : gotpl <631707329@qq.com>
;; -----
;;; init.el --- Description -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2023 gotpl
;;
;; Author: gotpl <631707329@qq.com>
;; Maintainer: gotpl <631707329@qq.com>
;; Created: 七月 27, 2023
;; Modified: 七月 27, 2023
;; Version: 0.0.1
;; Keywords: abbrev bib c calendar comm convenience data docs emulations extensions faces files frames games hardware help hypermedia i18n internal languages lisp local maint mail matching mouse multimedia news outlines processes terminals tex tools unix vc wp
;; Homepage: https://github.com/gotpl/init
;; Package-Requires: ((emacs "24.3"))
;;
;; This file is not part of GNU Emacs.
;;
;;; Commentary:
;;
;;  Description
;;
;;; Code:


(setq user-full-name "gotpl")
(setq user-mail-address "631707329@qq.com")
(add-hook 'emacs-startup-hook (lambda()
                                (setq gc-cons-threshold (* 20 1024 1024))))
;; (setq gc-cons-threshold most-positive-fixnum
;;       gc-cons-percentage 0.6)
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
;; (setq read-process-output-max (* 4 1024 1024))

(add-to-list 'load-path (expand-file-name "lisp" user-emacs-directory))


;; (let ((use-package-expand-minimally t))
;;   (message
;;    (macroexpand-all
;;     '(use-package avy
;;     :ensure t
;;         :defer t
;;        :config (+ 1 2)
;;        :init (+ 3 4)
;;        :config (+ 5 6)
;;        :init (+ 7 9)))))
;; elpaca 异步原因，use-package可能会在after-init之后才会执行，故在use-package中hook after-init可能无效，
;; 因为添加hook的时候after-init已经执行过了，无法执行新的hook, 这时候可以选择emacs-startup-hook
;; use-package 在:hook时，使用lambda检会立即加载包，即使你是在函数里面还未执行,或这函数里没有任何语句
;; 以下会尝试先加载test包，而不是在hook执行时才加载
;; (use-package test
;;   :hook (emacs-startup . (lambda () (test-xx))))
;; 想使用时再手动加载，需要把函数写道use-package外面
;; (defun load-test () (require 'test) (test-xxx))
;; (use-package test
;;   :hook (emacs-startup . load-test))


(defvar elpaca-installer-version 0.7)
(defvar elpaca-directory (expand-file-name "elpaca/" user-emacs-directory))
(defvar elpaca-builds-directory (expand-file-name "builds/" elpaca-directory))
(defvar elpaca-repos-directory (expand-file-name "repos/" elpaca-directory))
(defvar elpaca-order '(elpaca :repo "https://github.com/progfolio/elpaca.git"
                              :ref nil
                              ;; :depth 1
                              :files (:defaults "elpaca-test.el" (:exclude "extensions"))
                              :build (:not elpaca--activate-package)))
(let* ((repo  (expand-file-name "elpaca/" elpaca-repos-directory))
       (build (expand-file-name "elpaca/" elpaca-builds-directory))
       (order (cdr elpaca-order))
       (default-directory repo))
  (add-to-list 'load-path (if (file-exists-p build) build repo))
  (unless (file-exists-p repo)
    (make-directory repo t)
    (when (< emacs-major-version 28) (require 'subr-x))
    (condition-case-unless-debug err
        (if-let ((buffer (pop-to-buffer-same-window "*elpaca-bootstrap*"))
                 ((zerop (apply #'call-process `("git" nil ,buffer t "clone"
                                                 ,@(when-let ((depth (plist-get order :depth)))
                                                     (list (format "--depth=%d" depth) "--no-single-branch"))
                                                 ,(plist-get order :repo) ,repo))))
                 ((zerop (call-process "git" nil buffer t "checkout"
                                       (or (plist-get order :ref) "--"))))
                 (emacs (concat invocation-directory invocation-name))
                 ((zerop (call-process emacs nil buffer nil "-Q" "-L" "." "--batch"
                                       "--eval" "(byte-recompile-directory \".\" 0 'force)")))
                 ((require 'elpaca))
                 ((elpaca-generate-autoloads "elpaca" repo)))
            (progn (message "%s" (buffer-string)) (kill-buffer buffer))
          (error "%s" (with-current-buffer buffer (buffer-string))))
      ((error) (warn "%s" err) (delete-directory repo 'recursive))))
  (unless (require 'elpaca-autoloads nil t)
    (require 'elpaca)
    (elpaca-generate-autoloads "elpaca" repo)
    (load "./elpaca-autoloads")))
(add-hook 'after-init-hook #'elpaca-process-queues)
(elpaca `(,@elpaca-order))

;; (setq use-package-verbose t)
(setq package-enable-at-startup nil) 
(setq global-use-package-ensure t) ;; 内置了包则使用内置
(if (< emacs-major-version 29)
  (elpaca use-package)
  (progn
    (setq global-use-package-ensure t)))

(elpaca elpaca-use-package
  ;; Enable use-package :ensure support for Elpaca.
  (elpaca-use-package-mode)
  (setq elpaca-use-package-by-default t))
(elpaca-wait)

;; (defun show_benchmark ()
;;   (interactive)
;;   ;; (benchmark-init/deactivate)
;;   (benchmark-init/show-durations-tree))

;; (defun show_benchmark_tab ()
;;   (interactive)
;;   ;; (benchmark-init/deactivate)
;;   (benchmark-init/show-durations-tabulated))

;; (use-package benchmark-init
;;   :bind (("C-c C-g" . show_benchmark)
;;           ("C-c C-h" . show_benchmark_tab))

;;   :demand t
;;   :ensure (:host github :repo "dholm/benchmark-init-el")
;;   :config
;;   (add-hook 'emacs-startup-hook 'benchmark-init/deactivate)
;;   (benchmark-init/activate))
;; (elpaca-wait)

(use-package compat
  :defer t
  :ensure (:host github :repo "emacs-compat/compat"))

(use-package xr
  :defer t
  :ensure (:host github :repo "mattiase/xr"))
;; (use-package org
;;   :hook
;;   (org-mode . prettify-symbols-mode))
;; (elpaca-wait)

;; (use-package lazy-load
;;   :ensure (:host github :repo "manateelazycat/lazy-load"))
;; (elpaca-wait)

(use-package lazy-load
  :ensure (:type git :host github :repo "manateelazycat/lazy-load"))

(toggle-frame-maximized)
(setq emacs-python-path "")
(let ((emacs-python-env (getenv "EMACS_PYTHON_PATH"))
      (pyvenv-work-dir (getenv "WORKON_HOME")))
  (if (not pyvenv-work-dir)
      (setenv "WORKON_HOME" "~/miniconda3/envs"))
  (if (not emacs-python-env)
    (setq emacs-python-path (expand-file-name "~/miniconda3/envs/emacs/bin/python3.11"))
    (setq emacs-python-path emacs-python-env)))
;; (defun display-warning (type message &optional level buffer-name)
;;   (debug) ; 进入调试器
;;   ;; 调用原本的 display-warning 函数显示警告
;;   (display-warning type message level buffer-name))
;; (setq display-warning-function 'my-display-warning)


;; (use-package company
;;   :ensure (:host github :repo "company-mode/company-mode")
;;   :config
;;   (global-company-mode))

;; (use-package eglot
;;   :ensure nil
;;   :hook (prog-mode . eglot-ensure)
;;   )

(require 'init-base)
(require 'init-minibuffer)
(require 'init-evil)  
(require 'init-tools)
(require 'init-ui)
(require 'init-dev)
;; (require 'init-eaf)

(require 'init-funcs)
(require 'init-org)
(require 'init-keybinds)
(load custom-file)

(provide 'init)
;;; init.el ends here
